package com.burstly.lib.component;

import android.util.Log;
import com.burstly.lib.feature.FeatureFactory;
import com.burstly.lib.feature.networks.IAdaptorFactory;
import com.burstly.lib.util.LoggerExt;
import java.lang.reflect.Constructor;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

public final class AdaptorFactoryCache
{
  private static final Map<String, IAdaptorFactory> FACTORY_CACHE = new HashMap();
  private static final LoggerExt LOG = LoggerExt.getInstance();
  private static final String TAG = "AdaptorFactoryCache";

  public static void cacheFactory(String paramString, IAdaptorFactory paramIAdaptorFactory)
  {
    FACTORY_CACHE.put(paramString, paramIAdaptorFactory);
  }

  private static IAdaptorFactory createFactory(String paramString, Map<String, ?> paramMap)
  {
    try
    {
      LOG.logDebug("Creating factory for {0} ...", paramString, new Object[0]);
      Constructor localConstructor = Class.forName(paramString).getDeclaredConstructor(new Class[0]);
      localConstructor.setAccessible(true);
      IAdaptorFactory localIAdaptorFactory = (IAdaptorFactory)localConstructor.newInstance(new Object[0]);
      return localIAdaptorFactory;
    }
    catch (ClassNotFoundException localClassNotFoundException)
    {
      LOG.logWarning("AdaptorFactoryCache", "Unsupported network: {0}", new Object[] { paramString });
      return null;
    }
    catch (Exception localException)
    {
      while (true)
      {
        LOG.logWarning("AdaptorFactoryCache", "Could not instantiate factory class {0} for ''{0}''", new Object[] { paramString });
        LOG.logWarning("AdaptorFactoryCache", Log.getStackTraceString(localException), new Object[0]);
      }
    }
  }

  public static void destroy()
  {
    try
    {
      Iterator localIterator = FACTORY_CACHE.entrySet().iterator();
      while (localIterator.hasNext())
      {
        Map.Entry localEntry = (Map.Entry)localIterator.next();
        LoggerExt localLoggerExt = LOG;
        Object[] arrayOfObject = new Object[1];
        arrayOfObject[0] = localEntry.getKey();
        localLoggerExt.logInfo("AdaptorFactoryCache", "Destroying {0} factory", arrayOfObject);
        ((IAdaptorFactory)localEntry.getValue()).destroy();
      }
    }
    catch (Exception localException)
    {
      LOG.logThrowable("AdaptorFactoryCache", localException);
      try
      {
        while (true)
        {
          return;
          FACTORY_CACHE.clear();
        }
      }
      finally
      {
      }
    }
    finally
    {
      FACTORY_CACHE.clear();
    }
  }

  public static IAdaptorFactory getFactory(String paramString1, String paramString2, Map<String, ?> paramMap)
  {
    while (true)
    {
      IAdaptorFactory localIAdaptorFactory1;
      try
      {
        localObject2 = (IAdaptorFactory)FACTORY_CACHE.get(paramString1);
        if (localObject2 == null)
        {
          localIAdaptorFactory1 = FeatureFactory.getAdaptorFactoryFeature(paramString2);
          if (localIAdaptorFactory1 != null)
            break label100;
          LOG.logInfo("AdaptorFactoryCache", "No {0} factory in config.xml. Trying to load using classpath...", new Object[] { paramString1 });
          localIAdaptorFactory2 = createFactory(paramString1, paramMap);
          if (localIAdaptorFactory2 != null)
          {
            localObject2 = new AdaptorFactoryWrapper(localIAdaptorFactory2);
            cacheFactory(paramString1, (IAdaptorFactory)localObject2);
          }
        }
        else
        {
          return localObject2;
        }
      }
      finally
      {
      }
      Object localObject2 = localIAdaptorFactory2;
      continue;
      label100: IAdaptorFactory localIAdaptorFactory2 = localIAdaptorFactory1;
    }
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.burstly.lib.component.AdaptorFactoryCache
 * JD-Core Version:    0.6.2
 */